/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.elcom.emocbc.cbm.randomprogram;

import com.elcom.emocbc.broadcastscheduler.BroadcastScheduler;
import com.elcom.emocbc.broadcastscheduler.dao.ConnectionProvider;
import com.elcom.emocbc.broadcastscheduler.dao.ConnectionProviderManager;
import com.elcom.emocbc.dbmapping.persistence.DbAccess;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author GiangLT
 */
public class ScheduleRebuild implements Runnable {

    private final Logger logger = LoggerFactory.getLogger(ScheduleRebuild.class);

    @Override
    public void run() {
        try {
            
            BroadcastScheduler broadcastScheduler = new BroadcastScheduler();
            broadcastScheduler.rescheduleAllZones();
        } catch (Exception ex) {
            logger.error("", ex);
        }
    }

    public static void main(String[] args) {
        ConnectionProvider connectionProvider = new ConnectionProvider() {

            @Override
            public Connection aquireConnection() {
                try {
                    return DbAccess.getInstance().getConnection();
                } catch (SQLException ex) {
                    return null;
                }
            }

            @Override
            public void releaseConnection(Connection connection) {
                DbAccess.closeConnection(connection);
            }
        };
        ConnectionProviderManager.getInstance().setConnectionProvider(connectionProvider);
        BroadcastScheduler broadcastScheduler = new BroadcastScheduler();
        try {
            broadcastScheduler.rescheduleAllZones();
        } catch (SQLException ex) {
            java.util.logging.Logger.getLogger(ScheduleRebuild.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
